public class Solution643 {
    public double findMaxAverage(int[] nums, int k) {
        int sum=0;
        for (int i=0;i<k;i++){
            sum=sum+nums[i];
        }
        int max=sum;
        for (int i=k;i<nums.length;i++){
            sum-=nums[i-k];
            sum+=nums[i];
            max=Math.max(max,sum);
        }
        return max*1.0/k;
    }

    public static void main(String[] args) {
        System.out.println(new Solution643().findMaxAverage(new int[]{1,12,-5,-6,50,3},4));
    }
}
